<?php

/**
 * Created by PhpStorm.
 * Author: ls
 * Time: 2021/12/29 14:24
 * Desc: 供应中台配置获取
 */
class Model_Provider_Config extends ORM
{
    // 获取partner_id
    public static function get_partner_id($supplierId)
    {
        if ($supplierId) {
            $config = DB::select()
                ->from('supplier_provider_config')
                ->where('supplier_id', '=', $supplierId)
                ->execute()->current();
            if ($config) {
                return $config['partner_id'];
            }
        }
        return null;
    }

    // ota标识
    public static function get_ota_channel($otaCode)
    {
        include(Kohana::find_file('../newtravel/application/data', 'license'));
        if (isset($SerialNumber)) {
            return $SerialNumber . '-' . $otaCode;
        }
        return null;
    }

    // 解码ota值
    public static function decode_ota_channel($ota)
    {
        if ($ota) {
            $otaArr = explode('-', $ota);
            if (isset($otaArr[0]) && isset($otaArr[1])) {
                return array(
                    'licenseId' => $otaArr[0],
                    'otaCode' => $otaArr[1],
                );
            }
        }
        return null;
    }

    // 通过partner_id获取supplier_id
    public static function get_supplier_id_by_partner_id($partnerId){
        if ($partnerId) {
            $config = DB::select()
                ->from('supplier_provider_config')
                ->where('partner_id', '=', $partnerId)
                ->execute()->current();
            if ($config) {
                return $config['supplier_id'];
            }
        }
        return null;
    }
}